<template>
  <div class="home">
    <!--    <a-modal-->
    <!--      v-model="config.p_close"-->
    <!--      title="温馨提醒"-->
    <!--      :ok-button-props="{ props: { disabled: true } }"-->
    <!--      :cancel-button-props="{ props: { disabled: true } }"-->
    <!--    >-->
    <!--      <p>系统正在维护中，请稍后...</p>-->
    <!--    </a-modal>-->
    <HeaderBar />

    <div class="home-layout">
      <div class="home-left">
        <div class="side-card" style="height: 297px">
          <div class="card-title">最新发布</div>

          <div class="card-list">
            <div
              class="card-item"
              v-for="item in data.new_public"
              :key="item.ID"
              @click="goStore(item)"
            >
              {{ item.users.name }}
            </div>
          </div>

          <div class="card-more" @click="more('/new-public?type=最新发布')">
            更多...
          </div>
        </div>

        <div class="side-card" style="height: 297px">
          <div class="card-title">求购大厅</div>

          <div class="card-list">
            <div
              class="card-item"
              v-for="item in data.new_order"
              :key="item.ID"
              @click="goOrder(item)"
            >
              {{ item.buy_user.name }}
            </div>
          </div>

          <div class="card-more" @click="more('/orders')">
            更多...
          </div>
        </div>

        <div class="side-card" style="height: 297px">
          <div class="card-title">供应市场</div>

          <div class="card-list">
            <div
              class="card-item"
              @click="goGoods(item)"
              v-for="item in data.new_goods"
              :key="item.ID"
            >
              {{ item.title }}
            </div>
          </div>

          <div class="card-more" @click="more('/business')">
            更多...
          </div>
        </div>

        <div class="side-card" style="height: 297px">
          <div class="card-title">最新开通</div>

          <div class="card-list">
            <div
              class="card-item"
              v-for="item in data.new_index"
              :key="item.ID"
              @click="goStore(item)"
            >
              {{ item.users.name }}
            </div>
          </div>

          <div class="card-more" @click="more('/new-public?type=最新开通')">
            更多...
          </div>
        </div>

        <img
          src="./images/ad1.png"
          style="cursor: pointer;"
          @click="
            open(
              'https://zvib03.axshare.com/#id=48m7qu&p=%E4%B8%80%E8%A3%85%E4%BF%AE%E4%B8%9A%E4%B8%BB-%E9%A6%96%E9%A1%B5&dp=0&fn=0&sc=1&c=1'
            )
          "
        />
      </div>
      <div class="home-middle">
        <router-view />
      </div>

      <div class="home-right">
        <div class="side-card" v-if="isLogin()">
          <div class="info-wrapper">
            <img
              src="
                https://zszhuan.oss-cn-hangzhou.aliyuncs.com/images/0.jpg
              "
            />
            <div class="name-wrapper">
              <div class="name">{{ account.name }}</div>
              <div class="phone">{{ account.phone }}</div>
            </div>
          </div>
          <div
            class="quick-vip"
            @click="$router.push('/user/auth/step1')"
            v-if="account.applyStatus == 1"
          >
            立即升级认证企业，享受特色服务
          </div>
          <div
            class="quick-vip"
            @click="$router.push('/user-center')"
            v-if="account.applyStatus == 3"
          >
            个人会员中心
          </div>
          <div
            class="quick-vip"
            @click="$router.push('/user-center')"
            v-if="account.applyStatus == 2"
          >
            认证会员待审核
          </div>
        </div>

        <div class="side-card" v-else>
          <div class="welcome">欢迎您的到来</div>
          <div class="login-wrapper">
            <a-button type="primary" @click="$router.push('/user/login')"
              >请登录</a-button
            >
            <a-button @click="$router.push('/user/register')"
              >免费注册</a-button
            >
          </div>
        </div>
        <div class="side-card" style="height: 297px">
          <div class="card-title">企业列表</div>

          <!-- <a-carousel autoplay :dots="false"> -->
          <div class="card-list">
            <div
              class="card-item"
              v-for="item in data.new_users"
              :key="item.ID"
              @click="goStore(item)"
            >
              {{ item.name }}
            </div>
          </div>
          <!-- </a-carousel> -->

          <div class="card-more" @click="more('/new-company?type=企业列表')">
            更多...
          </div>
        </div>
        <div class="side-card support-unit">
          <div class="card-title">支持单位</div>

          <div class="card-list">
            <div class="card-item" @click="open('http://www.xmjchyxh.com/')">
              厦门市建筑材料行业协会
            </div>
            <div
              class="card-item"
              @click="open('http://xmjx.org/home/office/office_index/catid/40')"
            >
              厦门市建筑行业协会
            </div>
          </div>
        </div>

        <div class="side-card">
          <div class="card-title">实时数据</div>

          <div class="data-item">
            <div class="label">今年总成交量</div>
            <div class="value">
              <span>{{ sum | money }}</span
              >元
            </div>
          </div>
          <div class="data-item">
            <div class="label">今年总成交笔数</div>
            <div class="value green"><span>5</span></div>
          </div>
          <div class="data-item">
            <div class="label">本月总成交量</div>
            <div class="value"><span>50,000</span>元</div>
          </div>
          <div class="data-item">
            <div class="label">本月成交笔数</div>
            <div class="value green"><span>3</span></div>
          </div>
        </div>
        <div class="side-card" v-for="item in list2" :key="item.title">
          <div class="card-title">{{ item.title }}</div>

          <div class="card-list">
            <div
              class="card-item"
              v-for="inner in item.list"
              :key="inner.text"
              @click="$router.push(inner.path)"
            >
              {{ inner.text }}
            </div>
          </div>

          <div class="card-more" @click="$router.push(item.more)">更多...</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import HeaderBar from "@/components/headerBar/HeaderBar";
import { mapGetters, mapActions } from "vuex";
import { isLogin } from "@/utils/auth";
import { getIndex } from "@/api";
import storage from "@/utils/storage";
import { getConfig } from "@/api/account";
export default {
  components: {
    HeaderBar
  },
  computed: {
    ...mapGetters(["account"])
  },
  created() {
    isLogin() && this.getAccountAction();
    this.indexData();
  },
  data() {
    const data = storage.getItem("HOME_INDEX") || {};
    return {
      data,
      sum: 0,
      list2: [
        {
          title: "行业资讯",
          more: "/info",
          list: [
            {
              text: "[行业动态]祝贺厦门市思明区建筑行业...",
              title: "祝贺厦门市思明区建筑行业协会成立",
              path: "/info/祝贺厦门市思明区建筑行业协会成立"
            },
            {
              text: "[行业动态]厦门市建设局转发省住建厅..",
              title:
                "厦门市建设局转发省住建厅办公室关于考核聘任第四届福建省建设工程安全专项施工方案论证专家的通知",
              path:
                "/info/厦门市建设局转发省住建厅办公室关于考核聘任第四届福建省建设工程安全专项施工方案论证专家的通知"
            },
            {
              text: "[企业新闻]我会携手北京集美家居建材...",
              title:
                "厦门市建设局转发省住建厅办公室关于考核聘任第四届福建省建设工程安全专项施工方案论证专家的通知",
              path:
                "/info/我会携手北京集美家居建材商场举行首批“重质量.守诚信”商户授牌仪式"
            },
            {
              text: "[国内动态]绿色转型迫在眉睫急需新...",
              title: "祝贺厦门市思明区建筑行业协会成立",
              path: "/info/祝贺厦门市思明区建筑行业协会成立"
            },
            {
              text: "[行业动态]转发厦门市建设局转发省住..",
              title: "祝贺厦门市思明区建筑行业协会成立",
              path: "/info/祝贺厦门市思明区建筑行业协会成立"
            }
          ]
        },
        {
          title: "帮助",
          more: "/help",
          list: [
            {
              text: "如何注册成企业会员？",
              path: "/help?key=1"
            },
            {
              text: "如何申请项目信用？",
              path: "/help?key=2"
            },
            {
              text: "平台提供企业会员有哪些功能？",
              path: "/help?key=3"
            },
            {
              text: "平台提供企业会员有哪些功能？?",
              path: "/help?key=4"
            }
            // {
            //   text: "我们需要缴哪些交易费用吗？",
            //   path: "/help?key=5"
            // }
          ]
        }
      ]
    };
  },
  mounted() {},
  methods: {
    ...mapActions(["getAccountAction"]),
    more(item) {
      this.$router.push(item);
    },
    goStore(item) {
      this.$router.push("/company/" + (item.userId || item.ID));
    },
    goGoods(item) {
      storage.setItem("GOODS_ITEM", item);
      this.$router.push("/company/" + item.users.ID + "/goods/" + item.ID);
    },
    goOrder(item) {
      storage.setItem("ORDER_ITEM", item);
      this.$router.push("/orders/" + item.ID);
    },
    open(url) {
      window.open(url);
    },
    async indexData() {
      const rest = await getConfig();
      if (rest.data.p_close === "0") {
        this.config.p_close = false;
      } else {
        window.location.href =
          "https://yjc.xmzhuchen.com/tmp" + ".html?name=" + this.config.p_name;
        return;
      }
      const res = await getIndex({});
      this.data = res.data;
      this.sum = res.data.sum_money + 160000;
      storage.setItem("HOME_INDEX", this.data);
    },
    isLogin
  }
};
</script>

<style lang="less" scoped>
.home {
  .home-layout {
    display: flex;
    padding: 16px 0 3px;
    .home-left {
      width: 248px;
    }

    .home-middle {
      padding: 0 16px;
      flex: 1;
      width: @base-width - 248 - 248;
    }

    .home-right {
      width: 248px;

      .support-unit {
        .card-list {
          .card-item {
            font-weight: bold;
            padding-bottom: 2px;
            padding-top: 18px;
            font-size: 16px;
            color: @text-color;
          }
        }
      }

      .data-item {
        border-bottom: 1px solid @border-color;
        padding: 10px 8px 0px 12px;
        .label {
          color: @text-color-2;
          font-size: 15px;
        }

        .value {
          padding: 2px 0;

          &.green {
            span {
              color: green;
            }
          }

          span {
            color: @red;
            font-weight: bold;
            font-size: 20px;
          }
        }
      }
    }

    .card-title {
      font-size: 18px;
      font-weight: bold;
      padding-left: 16px;
      position: relative;
      &::before {
        position: absolute;
        content: "";
        width: 4px;
        background: @primary-color;
        left: 2px;
        top: 4px;
        bottom: 4px;
        border-radius: 4px;
      }
    }

    .side-card {
      background: @white;
      padding: 18px 12px;
      margin-bottom: 16px;
      display: flex;
      flex-direction: column;

      .card-list {
        flex: 1;
        .card-item {
          padding-left: 10px;
          border-bottom: 1px dashed @border-color;
          padding-top: 16px;
          padding-right: 8px;
          font-size: 15px;
          color: @text-color-1;
          cursor: pointer;
          padding-bottom: 1px;
          .ellipsis();

          &.null {
            color: transparent;
            border-bottom-color: transparent;
            padding-bottom: 5px;
          }
        }
      }

      .card-more {
        color: @text-color-2;
        text-align: right;
        margin-top: 12px;
        font-size: 15px;
        cursor: pointer;
        margin-right: 10px;
      }
    }

    .welcome {
      text-align: center;
      font-size: 16px;
      margin-top: 6px;
    }

    .login-wrapper {
      display: flex;
      padding: 20px 10px 10px;
      justify-content: space-between;
      .ant-btn {
        width: 94px;
        line-height: 38px;
        font-size: 14px;
        height: 38px;
      }
    }

    .info-wrapper {
      display: flex;
      align-items: center;

      img {
        width: 50px;
        border-radius: 50%;
      }

      .name-wrapper {
        margin-left: 10px;
        flex: 1;
        overflow: hidden;
        .name {
          font-weight: bold;
          font-size: 16px;
          .ellipsis();
        }

        .phone {
          color: @text-color-2;
          font-size: 13px;
          margin-top: 4px;
        }
      }
    }
  }
  .quick-vip {
    background: #e3ecfd;
    color: #316ccb;
    border: 1px solid #e3ecfd;
    font-size: 13px;
    text-align: center;
    line-height: 28px;
    margin-top: 10px;
    border-radius: 28px;
    cursor: pointer;
  }
}
</style>
